package main

import (
	"fmt"
	"time"
)

func worker(c chan int) {
	heartbeat := time.NewTimer(3 * time.Second)
	defer heartbeat.Stop()
	for {
		select {
		case <- c:
			fmt.Println("你好")
		case <- heartbeat.C:
			fmt.Println("我很好，你呢？")
			go func() {
				c <- 1000
			}()
		}
	}
}

func main() {
	c := make(chan int, 1)
	worker(c)
	//var wg sync.WaitGroup
	//go func() {
	//	defer wg.Done()
	//	c <- 100
	//}()
	//wg.Wait()

}
